package code.util.regex;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by chopin on 17/12/14.
 * JDK1.8
 * 测试正则表达式
 */
public class MatchTest {

    public static void main(String[] args){
        MatchTest test = new MatchTest();
        test.testNumber("234");
        test.testNumber("123.23");
        test.testNumber("0123");
        test.testNumber("123.");
    }

    public void testNumber(String str){

        Pattern pattern=Pattern.compile("^(([1-9]{1}\\d*)|([0]{1}))(\\.(\\d){1,2})?$"); // 判断小数点后2位的数字的正则表达式
        Matcher match=pattern.matcher(str);
        if(match.matches()==false){
            System.out.println(str+" , false");
        }else{
            System.out.println(str+" , true");
        }
    }

}
